package gameEngine.agents.choosingStrategy;

import java.util.ArrayList;
import org.apache.log4j.Logger;
import gameEngine.agents.teamMateModel.TeamMateModel;


/**
 * this strategy will use a different strategy according
 * to game turn
 * strategies and change of strategy turn is added manually
 * @author alon
 *
 */
public class ManuallAdaptiveStrategy extends AdaptiveStrategy {

	Logger log = Logger.getLogger(gameEngine.agents.choosingStrategy.StrategyFactory.class);
	int currentTurn=0;
	/**
	 * use current strategy to return id
	 */
	public void updateTurn(){
		currentTurn++;
	}
	
	public ManuallAdaptiveStrategy(){
		super();
	}
	
	public int chooseNextPlayer(TeamMateModel teamMateModel) {
		setCurrentStrategy();
		log.debug("Manual Adaptive using: "+strategies.get(currentStrategy).toString()+" at turn " + currentTurn);
		return strategies.get(currentStrategy).chooseNextPlayer(teamMateModel);
	}
	
	/**
	 * as we might not played for long period of time
	 * we need to find the next strategy to use. 
	 */
	private void setCurrentStrategy(){
		if(strategiesTurn.get(currentStrategy)<currentTurn){
			if(strategies.size()-1>currentStrategy){
				currentStrategy++;
				setCurrentStrategy();
			}
		}
	}
	
	//a copy constractur
	public ManuallAdaptiveStrategy(ArrayList<ChoosingStrategy> strats,ArrayList<Integer> turns){
		super(strats,turns);
		currentTurn=0;
	}

}
